<?php
include ('config.php');

$tbl_name=klant; // Table name

// email and password sent from form 
$myemail=$_POST['email']; 
$mypassword=$_POST['password'];

// To protect MySQL injection 
$myemail = stripslashes($myemail);
$mypassword = stripslashes($mypassword);
$myemail = mysql_real_escape_string($myemail);
$mypassword = mysql_real_escape_string($mypassword);
$mypassword=md5($mypassword);

$sql="SELECT * FROM $tbl_name WHERE email='$myemail' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
// If result matched $myemail and $mypassword, table row must be 1 row

if($count==1){
// Register $myemail, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION['myusername'] = "$myemail";
$_SESSION['mypassword'] = "$mypassword";
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>